cmake_minimum_required(VERSION 3.15)
project(HeartwallGraphService)

set(CMAKE_CXX_STANDARD 17)

# --- 1. 查找依赖库 ---
find_package(PkgConfig REQUIRED)

# 使用 pkg-config 查找 gRPC 和 Protobuf
pkg_check_modules(GRPC REQUIRED grpc++ grpc)
pkg_check_modules(PROTOBUF REQUIRED protobuf)

# 查找 libneo4j-client
pkg_check_modules(NEO4J REQUIRED neo4j-client)

# proto生成的 C++ 代码 - 使用明确的文件列表
file(GLOB PROTO_GEN_FILES "${CMAKE_CURRENT_SOURCE_DIR}/generated/*.cc")

# 服务接口类源文件 - 使用明确的文件列表
file(GLOB SERVICES_IMPLY_FILES "${CMAKE_CURRENT_SOURCE_DIR}/service/*/*.cpp")

# 工具类源文件 - 使用明确的文件列表
file(GLOB TOOLS_IMPLY_FILES "${CMAKE_CURRENT_SOURCE_DIR}/tools/*/*.cpp")

# 创建 gRPC 服务端可执行文件
add_executable(graph_server
    ${PROTO_GEN_FILES}
    ${TOOLS_IMPLY_FILES}
    ${SERVICES_IMPLY_FILES}
    main.cpp
)

target_link_libraries(graph_server
    ${GRPC_LIBRARIES}
    ${PROTOBUF_LIBRARIES}
    ${NEO4J_LIBRARIES}
    ssl
    crypto
    pthread
    dl
    z
)

# 创建 gRPC 客户端可执行文件
add_executable(graph_client
    ${PROTO_GEN_FILES}
    client.cpp
)

target_link_libraries(graph_client
    ${GRPC_LIBRARIES}
    ${PROTOBUF_LIBRARIES}
    ssl
    crypto
    pthread
    dl
    z
)

# add_executable(test
#     ${TOOLS_IMPLY_FILES}
#     neo4j_test.cpp
# )

# target_link_libraries(test
#     ${NEO4J_LIBRARIES}
#     ssl
#     crypto
#     pthread
#     dl
#     z
# )

# 添加头文件目录
target_include_directories(graph_server PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_CURRENT_SOURCE_DIR}/generated
    ${NEO4J_INCLUDE_DIRS}
    ${GRPC_INCLUDE_DIRS}
    ${PROTOBUF_INCLUDE_DIRS}
)
